package com.bob.web.controller;

import com.bob.web.common.constant.CodeConstant;
import com.bob.web.common.constant.ResponseResult;
import org.springframework.boot.autoconfigure.web.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 名称: ErrorController<br>
 * 描述:用来处理404页面<br>
 * 类型: JAVA<br>
 * 最近修改时间:2017/7/7 15:53<br>
 *
 * @author BoYangsh
 * @version [版本号, V1.0]
 * @since 2017/7/7 15:53
 */
@RestController
public class MyErrorController extends BaseController implements ErrorController {

	/**
	 * 404异常
	 * @param response
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "404")
	public ResponseResult error(HttpServletResponse response, HttpServletRequest request) {
		// 错误处理逻辑
		return new ResponseResult(CodeConstant.PAGE_NOT_EXISTED);
	}

	/**
	 * 未授权异常
	 * @return
	 */
	@RequestMapping(value = "no_auth")
	public ResponseResult noAuth() {
		return new ResponseResult(CodeConstant.NO_AUTH);
	}

	/**
	 * 未登录异常
	 * @return
	 */
	@RequestMapping(value = "no_login")
	public ResponseResult noLogin() {
		return new ResponseResult(CodeConstant.NO_LOGIN);
	}


	@Override
	public String getErrorPath() {
		return "/404";
	}
}
